<?php
class refund{
/**
	 * 订单退款
	 * @param unknown $refund
	 */
	public function order_refund($refund_id){
		$result = array();
		$model_refund = Model('refund_return');
		$condition = array();
		$condition['refund_id'] = intval($refund_id);
		$refund = $model_refund->getRefundReturnInfo($condition);//退款订单信息
		
		$model_order = Model('order');
		$order_info = $model_order->getOrderInfo(array('order_id'=>$refund['order_id']));//订单信息
		if($order_info['payment_code'] == 'wxpay_jsap'){
			if(empty($refund['pay_refund_id'])){
				$payment_api = $this->_get_payment_api('wxpay');
				$wx_result = $payment_api->refundOrder($order_info,$refund);
				if($wx_result['result_code'] == 'SUCCESS'){
					$result['status'] = 1;
					$result['out_refund_id'] = $wx_result['refund_id'];
				}else{
					$result['status'] = 0;
					$result['msg'] = $wx_result['err_code_des'];
				}
			}
		}
		return $result;
	}
	
	/**
	 * 获取支付接口实例
	 */
	private function _get_payment_api($payment_code) {
		$inc_file = BASE_PATH.DS.'api'.DS.'payment'.DS.$payment_code.DS.$payment_code.'.php';
		if(is_file($inc_file)) {
			require($inc_file);
		}
		
		$payment_api = new $payment_code();
		return $payment_api;
	}
}
?>